package com.itheima.d3_stream;

import java.util.*;
import java.util.stream.Stream;

/*
        目标：掌握Stream流的创建。

        1 单列集合获取Stream流
        2 双列集合获取Stream流
        3 数组获取Stream流
        4 同一种类型多个数据获取Stream流
 */
public class StreamTest2 {
    public static void main(String[] args) {
        // 1、如何获取List集合的Stream流？
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰","张无忌","周芷若","赵敏","张强");

//        1 单列集合获取Stream流
        names.stream().forEach(s -> System.out.println(s));

//        2 双列集合获取Stream流
        HashMap<String, String> map = new HashMap<>();
        map.put("111","2222");
        map.put("333","24745");
        map.put("444","12372");
        map.put("555","277");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        entries.stream().forEach(s -> System.out.println(s.getKey()+":"+s.getValue()));
        Set<String> keys = map.keySet();
        System.out.println("======================");
        keys.stream().forEach(s-> System.out.println(s));
//        3 数组获取Stream流

        String[] arr = {"aaa","bbb","ccc","ddd"};
        Stream<String> stream = Arrays.stream(arr);
        stream.forEach(s -> System.out.println(s));
//        4 同一种类型多个数据获取Stream流
        Stream<String> st = Stream.of("hhhh", "sssss", "sslslsl", "NPNPNPNPNPN");
        st.forEach(s -> System.out.println(s));

    }
}
